CTRL_SRCS-y += xc_mem_paging.c
CTRL_SRCS-y += xc_memshr.c
CTRL_SRCS-y += xc_hcall_buf.c
+CTRL_SRCS-y += xc_foreign_memory.c
CTRL_SRCS-y += xtl_core.c
CTRL_SRCS-y += xtl_logger_stdio.c
CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
--- /dev/null
+/******************************************************************************
+ * xc_foreign_memory.c
+ *
+ * Functions for mapping foreign domain's memory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "xc_private.h"
+
+void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
+ xen_pfn_t *arr, int num )
+{
+ return xch->ops->u.privcmd.map_foreign_batch(xch, xch->ops_handle,
+ dom, prot, arr, num);
+}
+
+void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
+{
+ return xch->ops->u.privcmd.map_foreign_bulk(xch, xch->ops_handle,
+ dom, prot, arr, err, num);
+}
return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
}
-static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom,
+static int xc_map_foreign_batch_single(int fd, uint32_t dom,
xen_pfn_t *mfn, unsigned long addr)
{
privcmd_mmapbatch_t ioctlx;
{
*mfn ^= XEN_DOMCTL_PFINFO_PAGEDTAB;
usleep(100);
- rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+ rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
}
while ( (rc < 0) && (errno == ENOENT) );
return rc;
}
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
+static void *linux_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ xen_pfn_t *arr, int num)
{
+ int fd = (int)h;
privcmd_mmapbatch_t ioctlx;
void *addr;
int rc;
- addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, xch->fd, 0);
+ addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0);
if ( addr == MAP_FAILED )
{
PERROR("xc_map_foreign_batch: mmap failed");
ioctlx.addr = (unsigned long)addr;
ioctlx.arr = arr;
- rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+ rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
if ( (rc < 0) && (errno == ENOENT) )
{
int i;
XEN_DOMCTL_PFINFO_PAGEDTAB )
{
unsigned long paged_addr = (unsigned long)addr + (i << PAGE_SHIFT);
- rc = xc_map_foreign_batch_single(xch, dom, &arr[i],
+ rc = xc_map_foreign_batch_single(fd, dom, &arr[i],
paged_addr);
if ( rc < 0 )
goto out;
return addr;
}
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
- const xen_pfn_t *arr, int *err, unsigned int num)
+static void *linux_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
{
+ int fd = (int)h;
privcmd_mmapbatch_v2_t ioctlx;
void *addr;
unsigned int i;
int rc;
addr = mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, MAP_SHARED,
- xch->fd, 0);
+ fd, 0);
if ( addr == MAP_FAILED )
{
PERROR("xc_map_foreign_batch: mmap failed");
ioctlx.arr = arr;
ioctlx.err = err;
- rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
+ rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
if ( rc < 0 && errno == ENOENT )
{
ioctlx.err = err + i;
do {
usleep(100);
- rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
+ rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx);
} while ( rc < 0 && err[i] == -ENOENT );
}
}
ioctlx.addr = (unsigned long)addr;
ioctlx.arr = pfn;
- rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
+ rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
rc = rc < 0 ? -errno : 0;
err[i] = rc ?: -EINVAL;
continue;
}
- rc = xc_map_foreign_batch_single(xch, dom, pfn + i,
+ rc = xc_map_foreign_batch_single(fd, dom, pfn + i,
(unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT));
if ( rc < 0 )
{
.u.privcmd = {
.hypercall = &linux_privcmd_hypercall,
+
+ .map_foreign_batch = &linux_privcmd_map_foreign_batch,
+ .map_foreign_bulk = &linux_privcmd_map_foreign_bulk,
},
};
return call.result;
}
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
- const xen_pfn_t *arr, int *err, unsigned int num)
+static void *minios_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
{
unsigned long pt_prot = 0;
#ifdef __ia64__
return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
}
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
+static void *minios_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ xen_pfn_t *arr, int num)
{
unsigned long pt_prot = 0;
int err[num];
.u.privcmd = {
.hypercall = &minios_privcmd_hypercall,
+
+ .map_foreign_batch = &minios_privcmd_map_foreign_batch,
+ .map_foreign_bulk = &minios_privcmd_map_foreign_bulk,
},
};
/* stub for all not yet converted OSes */
-void *
-#ifdef __GNUC__
-__attribute__((__weak__))
-#endif
-xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
- const xen_pfn_t *arr, int *err, unsigned int num)
+void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num)
{
xen_pfn_t *pfn;
unsigned int i;
return hypercall->retval;
}
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
+static void *netbsd_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ xen_pfn_t *arr, int num)
{
+ int fd = (int)h;
privcmd_mmapbatch_t ioctlx;
void *addr;
addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0);
ioctlx.dom=dom;
ioctlx.addr=(unsigned long)addr;
ioctlx.arr=arr;
- if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+ if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
{
int saved_errno = errno;
PERROR("xc_map_foreign_batch: ioctl failed");
.u.privcmd = {
.hypercall = &netbsd_privcmd_hypercall;
+
+ .map_foreign_batch = &netbsd_privcmd_map_foreign_batch,
+ .map_foreign_bulk = &xc_map_foreign_bulk_compat,
},
};
return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
}
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
- xen_pfn_t *arr, int num)
+static void *solaris_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ xen_pfn_t *arr, int num)
{
+ int fd = (int)h;
privcmd_mmapbatch_t ioctlx;
void *addr;
- addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xch->fd, 0);
+ addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, fd, 0);
if ( addr == MAP_FAILED )
return NULL;
ioctlx.dom=dom;
ioctlx.addr=(unsigned long)addr;
ioctlx.arr=arr;
- if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
+ if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
{
int saved_errno = errno;
PERROR("XXXXXXXX");
.u.privcmd = {
.hypercall = &solaris_privcmd_hypercall;
+
+ .map_foreign_batch = &solaris_privcmd_map_foreign_batch,
+ .map_foreign_bulk = &xc_map_foreign_bulk_compat,
},
};
union {
struct {
int (*hypercall)(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall);
+
+ void *(*map_foreign_batch)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
+ xen_pfn_t *arr, int num);
+ void *(*map_foreign_bulk)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num);
} privcmd;
} u;
};
/* All backends, including the builtin backend, must supply this structure. */
extern xc_osdep_info_t xc_osdep_info;
+/* Stub for not yet converted OSes */
+void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
+ uint32_t dom, int prot,
+ const xen_pfn_t *arr, int *err, unsigned int num);
+
#endif
/*